﻿using Example;
using NewWms;
using NewWms.Apiservice;
using NewWms.Apiservice.InPut;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.Xml;
using System.Text;
using System.Threading.Tasks;
using wms_wpf.Apiservice;
using wms_wpf.Views;

namespace wms_wpf.ViewModels
{
    public class LoginViewModel : BindableBase, IDialogAware
    {

        //define
        public LoginViewModel(LoginView loginView )
        {
            LoginCommand = new DelegateCommand(Login);
            this.LoginView = loginView;
            Service= new UserService();
        }
        private LoginView LoginView { get; set; }
        public event Action<IDialogResult> RequestClose;
        public DelegateCommand LoginCommand { get; set; }
        public MyUserService Service { get; set; }
        private string username;
        public string  UserName
        {
            get { return username; }
            set { username = value;RaisePropertyChanged(); }
        }
        private string  password;
        public string  PassWord
        {
            get { return password; }
            set { password = value;RaisePropertyChanged(); }
        }

        //功能
        public async void Login()
        {
            bool result = await Service.LoginUser(new InPut_UserService2() { password = LoginView.password.Password, username = UserName });
            if (result) RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
        }//登录
        //主页设置
        public string Title { get; set; } = "wms";
        public bool CanCloseDialog()
        {
            return true;
        }
        public void OnDialogClosed()
        {
            
        }
        public void OnDialogOpened(IDialogParameters parameters)
        {
            
        }
    }
}
